package com.projects.android.dto;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class OrdersDTO {
	private int ID;
	private int IDRestaurant;
	private String IDUsers;
	private String OrderDate;
	private String ShipDate;
	private boolean IsVerified;
	private boolean IsShipped;
	private String DeliveryNote;
	private String ReceiverAddress;
	private String ReceiverName;
	private String ReceiverPhone;
	private ArrayList<OrderDetailDTO> OrderDetails;
	private RestaurantDTO Restaurant;
	
	public void initObject(JSONObject data){
		try {
			ID = Integer.valueOf(data.getString("ID"));
			IDRestaurant = Integer.valueOf(data.getString("IDRestaurant"));
			IDUsers = data.getString("IDUsers");
			OrderDate = data.getString("OrderDate");
			ShipDate = data.getString("ShipDate");
			IsVerified = Boolean.valueOf(data.getString("IsVerified"));
			IsShipped = Boolean.valueOf(data.getString("IsShipped"));
			DeliveryNote = data.getString("DeliveryNote");
			ReceiverName = data.getString("ReceiverName");
			ReceiverPhone = data.getString("ReceiverPhone");
			ReceiverAddress = data.getString("ReceiverAddress");
			OrderDetails = new ArrayList<OrderDetailDTO>();
			JSONArray arrData = new JSONArray(data.getString("OrderDetails"));
			// Loop for all reveived objects
			for (int i = 0; i < arrData.length(); i++) {
				JSONObject dataChild = (JSONObject) arrData.get(i);
				OrderDetailDTO dto = new OrderDetailDTO();
				dto.initObject(dataChild);
				OrderDetails.add(dto);
			}
			JSONObject restaurant = new JSONObject(data.getString("Restaurant"));
			Restaurant = new RestaurantDTO();
			Restaurant.setID(Integer.valueOf(restaurant.getString("ID")));		
			Restaurant.setName(restaurant.getString("Name"));
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			Log.e("Init CityDTO", e.toString());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.e("Init CityDTO", e.toString());
		}
	}
	
	public int getID() {
		return ID;
	}
	public void setID(int iD) {
		ID = iD;
	}
	public String getIDUsers() {
		return IDUsers;
	}
	public void setIDUsers(String iDUsers) {
		IDUsers = iDUsers;
	}
	public String getOrderDate() {
		return OrderDate;
	}
	public void setOrderDate(String orderDate) {
		OrderDate = orderDate;
	}
	public ArrayList<OrderDetailDTO> getOrderDetails() {
		return OrderDetails;
	}
	public void setOrderDetails(ArrayList<OrderDetailDTO> orderDetails) {
		OrderDetails = orderDetails;
	}

	public boolean getIsVerified() {
		return IsVerified;
	}

	public void setIsVerified(boolean isVerified) {
		IsVerified = isVerified;
	}

	public boolean getIsShipped() {
		return IsShipped;
	}

	public void setIsShipped(boolean isShipped) {
		IsShipped = isShipped;
	}

	public int getIDRestaurant() {
		return IDRestaurant;
	}

	public void setIDRestaurant(int iDRestaurant) {
		IDRestaurant = iDRestaurant;
	}

	public String getShipDate() {
		return ShipDate;
	}

	public void setShipDate(String shipDate) {
		ShipDate = shipDate;
	}

	public String getDeliveryNote() {
		return DeliveryNote;
	}

	public void setDeliveryNote(String deliveryNote) {
		DeliveryNote = deliveryNote;
	}

	public String getReceiverAddress() {
		return ReceiverAddress;
	}

	public void setReceiverAddress(String receiverAddress) {
		ReceiverAddress = receiverAddress;
	}

	public String getReceiverName() {
		return ReceiverName;
	}

	public void setReceiverName(String receiverName) {
		ReceiverName = receiverName;
	}

	public String getReceiverPhone() {
		return ReceiverPhone;
	}

	public void setReceiverPhone(String receiverPhone) {
		ReceiverPhone = receiverPhone;
	}

	public RestaurantDTO getRestaurant() {
		return Restaurant;
	}

	public void setRestaurant(RestaurantDTO restaurant) {
		Restaurant = restaurant;
	}
}
